package cn.lingyangwl.boot.modules;

import cn.lingyangwl.agile.system.model.entity.SysUser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;

import java.util.concurrent.TimeUnit;

/**
 * @author shenguangyang
 */
public class JsonConfigPayloadListener {

    /**
     * 测试json性能
     * @throws JsonProcessingException
     */
    @Test
    public void test() throws JsonProcessingException, InterruptedException {
        ObjectMapper mapper = new ObjectMapper();
        for (int j = 0; j < 10; j++) {
            new Thread(() -> {
                try {
                    long s1 = System.currentTimeMillis();
                    for (int i = 0; i < 20; i++) {
                        long start = System.currentTimeMillis();
                        SysUser sysUser = new SysUser();
                        sysUser.setUserId(12L);
                        sysUser.setLastLoginIp("127.0.0.1");
                        sysUser.setEmail("shenguangyang@foxmail.com");
                        sysUser.setUserName("admin");
//                        String json = mapper.writeValueAsString(sysUserPO);
//                        JSONObject item = JSONObject.parseObject(json, Feature.OrderedField);
                        //Console.log("time: {} ms, json: {}", System.currentTimeMillis() - start, json);
                    }
                    long end = System.currentTimeMillis();
                    System.out.println("time: " + (end - s1) + " ms");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }).start();
        }

        TimeUnit.SECONDS.sleep(10);
    }
}
